﻿using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevTeam;
using Fatura.Properties;
using System;
using System.Data;
using System.Drawing;


namespace Fatura
{
    public class FaturaRibbon
    {
        public static int[] TeamLeaders = new int[] { 3, 16, 22, 26, 7, 13, 11 };

        public class Departman
        {
            public const int KumasDepo = 6;
            public const int AksesuarSatinalma = 2;
        }

        public static RibbonManager rm;
        public static void Init()
        {
            RibbonControl RibbonControl = Session.MainForm.Ribbon;
            Session.RibbonControl = Session.MainForm.Ribbon;
            RibbonControl.Pages.Clear();
            Image newIcon = Resources.promotion;
            Image listIcon = Resources.TableHS;

            rm = new RibbonManager(RibbonControl);
            rm.MenuClicked += RibbonManager_MenuClicked;
            RibbonManager.Page page;
            RibbonManager.Group group;
            RibbonManager.Menu menu;
            RibbonManager.SubMenu subMenu;

            #region Ana Sayfa
            page = rm.AddPage(RibbonControl, "Ana Sayfa");
            group = page.AddGroup("Temel");

            group.AddMenu("Şablon Kaydet", Resources.ParametersLarge, typeof(Sablon)).SetVisibleFor(217);
            group.AddMenu("Fatura Kaydet", Resources.US_dollar, typeof(FaturaKaydet));
            group.AddMenu("Faturalar", Resources.report, typeof(Faturalar));
            group.AddMenu("Müşteriler", Resources.Login_Manager, typeof(Musteriler));
            
            menu = group.AddMenu("Refresh Lookups", Resources.refresh);
            menu.AddCustomAction(Session.MainForm.RefreshData);
            menu.BeginGroup();

            menu = group.AddMenu("Pencereler", Resources.ParametersLarge);
            menu.BeginGroup();

            subMenu = menu.AddSubMenu("Diğerlerini Kapat", Resources.WatermarkLarge_16);
            subMenu.AddCustomAction(Session.MainForm.DigerleriniKapat);

            subMenu = menu.AddSubMenu("Hepsini Kapat", Resources.delete_16);
            subMenu.AddCustomAction(Session.MainForm.HepsiniKapat);

            menu = group.AddMenu("Müşteri Bazlı İşlemler", Resources.Login_Manager);
            menu.AddCustomAction(MusteriBazli);
            menu.BeginGroup();

            menu = group.AddMenu("Sezon Bazlı İşlemler", Resources.Actions_flag_red_icon);
            menu.AddCustomAction(SezonBazli);
            menu.SetVisibleFor(5);

            menu = group.AddMenu("Raporlar", Resources.report);
            menu.AddCustomAction(Raporlar);

            #endregion



            foreach (RibbonPage ribbonPage in RibbonControl.Pages)
            {
                foreach (RibbonPageGroup ribbonGroup in ribbonPage.Groups)
                {
                    ribbonGroup.Visible = false;
                    foreach (object ribbonMenu in ribbonGroup.ItemLinks)
                    {
                        if (ribbonMenu is BarButtonItemLink)
                            if (((BarButtonItemLink)ribbonMenu).Visible)
                            {
                                ribbonGroup.Visible = true;
                                break;
                            }
                    }
                }

                if (ribbonPage.Visible)
                {
                    ribbonPage.Visible = false;
                    foreach (RibbonPageGroup ribbonGroup in ribbonPage.Groups)
                    {
                        if (ribbonGroup.Visible)
                        {
                            ribbonPage.Visible = true;
                            break;
                        }
                    }
                }
            }

            RibbonControl.ForceInitialize();
        }


        static void RibbonManager_MenuClicked(Type type, params object[] parameters)
        {
            Session.MainForm.ShowMdiChildForm(type, parameters);
        }

        public static void Raporlar()
        {
            Session.MainForm.ShowDockPanel("Raporlar");
        }

        public static void SezonBazli()
        {
            Session.MainForm.ShowDockPanel("Sezon Bazlı İşlemler");
        }

        public static void MusteriBazli()
        {
            Session.MainForm.ShowDockPanel("Müşteri Bazlı İşlemler");
        }

    }
}